//
//  CardViewController.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/8/30.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit
import hpple
import SwiftyJSON

class CardViewController: KMViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.title = creditCard
        addSubView()
        
    }
    
    
    
    //MARK: 添加子视图
    fileprivate func addSubView() {
        
        let cardView = CardScrollView()
        cardView.cardDelegate = self
        self.view.addSubview(cardView)
        
        cardView.bankView.moreButton.addTarget(self, action: #selector(moreBankType), for: .touchUpInside)
        cardView.themeView.moreButton.addTarget(self, action: #selector(moreThemeType), for: .touchUpInside)
        cardView.recommendView.footerBtn.addTarget(self, action: #selector(moreRecommend), for: .touchUpInside)
        
        cardView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview().inset(UIEdgeInsets.zero)
        }
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    //MARK: 更多银行
    @objc fileprivate func moreBankType() {
        
        let handleVC = HandleViewController.init()
        handleVC.hidesBottomBarWhenPushed = true
        self.navigationController?.pushViewController(handleVC, animated: true)
    }
    
    //MARK: 更多主题
    @objc fileprivate func moreThemeType() {
        
        let handleVC = HandleViewController.init()
        handleVC.hidesBottomBarWhenPushed = true
        self.navigationController?.pushViewController(handleVC, animated: true)
    }
    
    //MARK: 更多推荐
    @objc fileprivate func moreRecommend() {
        
        let handleVC = HandleViewController.init()
        handleVC.hidesBottomBarWhenPushed = true
        self.navigationController?.pushViewController(handleVC, animated: true)
    }

}

extension CardViewController : CardScrollViewDelegate {
    
    //MARK: 免费申请详情
    func showRecommendDetails(id: String,urlStr: String,title:String) {
        
        KMTool.generateRecords(idString: id)
      
        let webDetailsVC = WebDetailsViewController.init(urlString: urlStr)
        webDetailsVC.hidesBottomBarWhenPushed = true
        self.navigationController?.pushViewController(webDetailsVC, animated: true)
    }
    
    //MARK:  显示新闻详情
    func showNewsDetails(urlStr: String,title:String) {
        
        let webVC = WebViewController.init(urlString: urlStr,title:title)
        webVC.hidesBottomBarWhenPushed = true
        self.navigationController?.pushViewController(webVC, animated: true)
    }
    
    //MARK: 选择服务类型
    func selectType(title: String) {

        switch title {
        case cardArtifact://办卡神器
            let cardToolVC = CardToolViewController.init(title: title)
            cardToolVC.hidesBottomBarWhenPushed = true
            self.navigationController?.pushViewController(cardToolVC, animated: true)
        case liftingCheats://提额秘籍
            let improveVC = ImproveViewController.init(urlString: "/mobile/forehead", title: title)
            improveVC.hidesBottomBarWhenPushed = true
            self.navigationController?.pushViewController(improveVC, animated: true)
        case progressInquiry://进度查询
            let serviceVC = ServiceViewController.init(urlString: "/mobile/schedule", title: title)
            serviceVC.hidesBottomBarWhenPushed = true
            self.navigationController?.pushViewController(serviceVC, animated: true)
        case creditCardActivation://信用卡激活
            let serviceVC = ServiceViewController.init(urlString: "/mobile/activation", title: title)
            serviceVC.hidesBottomBarWhenPushed = true
            self.navigationController?.pushViewController(serviceVC, animated: true)
        case creditCardTopic://信用卡专题
            let specialVC = SpecialViewController.init(title: title, urlString: "/mobile/zhuanti")
            specialVC.hidesBottomBarWhenPushed = true
            self.navigationController?.pushViewController(specialVC, animated: true)
        default:
            break
        }
        
        
    }
    
    //MARK: 选择银行类型
    func selectBankType(title: String) {
        
        let handleVC = HandleViewController.init(bankType: title)
        handleVC.hidesBottomBarWhenPushed = true
        self.navigationController?.pushViewController(handleVC, animated: true)
    }
    
    //MARK: 选择卡片类型
    func selectCardType(title: String) {
        
        let handleVC = HandleViewController.init(useType: title)
        handleVC.hidesBottomBarWhenPushed = true
        self.navigationController?.pushViewController(handleVC, animated: true)
    }
}
